﻿package extremefx.geom {
	import extremefx.ICloneable;
	import extremefx.IEquatable;

	import flash.geom.Point;

	/**
	 * @author Marcelo Volmaro
	 */
	public class SizeF implements ICloneable, IEquatable{
		public var width:Number;
		public var height:Number;
		
		/**
		 * @param pArgs [Size]|[Point]|[x:Number, y:Number]
		 */
		public function SizeF(... pArgs) {
			var arg0:* = pArgs[0];
			
			if (pArgs.length == 1){
				if (arg0 is Size){
					setSize(arg0.width, arg0.height);
					
				} else if (arg0 is Point){
					setSize(arg0.x, arg0.y);
				}
				
			} else {
				setSize(arg0, pArgs[1]);
			}
		}
		
		public function clone():Object {
			return new SizeF(this);
		}
		
		public function toSize():Size{
			return new Size(width, height);
		}
		
		public function toPoint():Point {
			return new Point(width, height);
		}
				
		public function setSize(pWidth:Number, pHeight:Number):void{
			width = pWidth;
			height = pHeight;
		}
		
		public function times(pFactor:int):SizeF{
			return new SizeF(width * pFactor, height * pFactor);
		}
		
		public function divide(pFactor:int):SizeF{
			return new SizeF(width / pFactor, height / pFactor);
		}
		
		public function plus(pSize:SizeF):SizeF {
			return new SizeF(width + pSize.width, height + pSize.height);
		}
		
		public function minus(pSize:SizeF):SizeF {
			return new SizeF(width - pSize.width, height - pSize.height);
		}
		
		public function round():Size {
			return new Size(Math.round(width), Math.round(height));
		}
		
		public function ceiling():Size {
			return new Size(Math.ceil(width), Math.ceil(height));
		}
		
		public function truncate():Size {
			return new Size(int(width), int(height));
		}
		
		public function equals(pObj:*):Boolean {
			if (pObj is SizeF){
				var o:SizeF = SizeF(pObj);
				return o.width == width && o.height == height;
			}
			
			return false;
		}
		
		public function toString():String {
			return "[SizeF, w:"+width+", h:"+height+"]";
		}
	}
}
